#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, i, k, min = 1000000, sum = 0, flag;
  	long long m;
	cin >> n >> m;
  	int a[n+1];
	long long  b[n+1];
	for(i=1; i<=n; i++)
	{
		cin >> a[i];
		if(a[i] < min)
			min = a[i];
	}
	sum += min;
	for(i=1; i<=n; i++)
	{
		cin >> b[i];
		a[i] -= min;
	}
	while(m)
	{
		flag = 0;
		for(int k=1; k<=n; k++)
		{
			if(a[k] == 0)
			{
				if(b[k] == 0 || m == 0)
				{
					flag = 1;
					break;
				}
				else if(b[k] > 0 && m > 0)
				{
					b[k]--;
					m--;
				}
			}
			else
				a[k]--;
		}
		if(flag)
			break;
		sum++;
	}
	cout << sum;

}
